Repository navigation
The sql.js connection keeps its prepared statements - #5
Open
sleeper-luke wants to merge 1 commit into
Open
sleeper-luke wants to merge 1 commit into
sleeper-luke wants to merge 1 commit into
Conversation
…piles each insert once rather than once per row Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before:
openSqlJsConnection, the connection a web app binds its stores to, prepared and freed a statement on every call. An ingest runs one insert per row, so a 12,000-player body compiled the sameINSERT12,000 times, all on the main thread.After: Each database keeps its prepared statements by SQL, up to 256, freeing the least recently used. A statement is reset after every run, so none is left holding its table, which SQLite needs before it drops or alters one, as a schema rebuild does.
Measured: app-shared's real stores over this connection, with production bodies. JS is the store's parse and
toRows; SQL is timed by SQLite's own clock.The SQL step drops 16–39%. That's main-thread time saved on every browser ingest, in app-web today and in sleeper-web once it binds stores.
Tests: four new cases in
src/sqljs/sqljs_connection.test.ts: a statement is prepared once across runs; a statement runs again after failing partway; a table can be dropped and rebuilt after statements read it; and the cache stays bounded, freeing what it evicts.yarn test(789 passed),yarn test:prod(771 passed) andyarn typecheckpass locally.